//数据库增删改操作
let db = require('../db/index')

exports.get = (req, res) => {        //获取表全部数据
    var sql = 'select * from T_Stu'
    db.query(sql, [req.query.perno,req.query.pername,req.query.persex,req.query.floorno,req.query.dormno,
        req.query.phonenum,req.query.department,req.query.peofessional,req.query.classnum],(err, data) => {
        if(err) {
            return res.send('错误：' + err.message)
        }
        res.send(data)
    })
}

exports.handleDelete = (req, res) => {        //通过perno删除数据
    var sql = 'delete from T_Stu where perno = ?'
    db.query(sql, [req.query.perno], (err, data) => {
        if(err) {
            return res.send('错误：' + err.message)
        }
        res.send({
            status: 200,
            message: '删除成功'
        })
    })
}
//添加
exports.addstu = (req,res) =>{
    var sql='insert into T_Stu (perno,pername,persex,floorno,dormno,phonenum,department,peofessional,classnum,) value (?,?,?,?,?,?,?,?,?)'
    db.query(sql,[req.query.perno,req.query.pername,req.query.persex,req.query.floorno,req.query.dormno,
        req.query.phonenum,req.query.department,req.query.peofessional,req.query.classnum],(err,data)=>{
            if(err){
                return res.send('错误：'+err.message)
            }
            res.send({
                status:200,
                message:'添加成功'
            })
        })
}

//修改
exports.handleEdit=(req,res)=>{
    var sql = 'updata T_Stu set perno=?,'
    db.query(sql,[req.query.perno,req.query.pername,req.query.persex,req.query.floorno,req.query.dormno,
        req.query.phonenum,req.query.department,req.query.peofessional,req.query.classnum],(err,data)=>{
            if(err){
                return res.send('错误：'+err.message)
            }
            res.send({
                status:200,
                message:'修改成功'
            })
        })
}
